<template>
	<div id="">
		<el-form :inline="true"  class="demo-form-inline">
		  <el-form-item label="采购清单号">
		    <el-input v-model="pnum" placeholder="采购清单号" ref="pnum"></el-input>
		  </el-form-item>
		  
		  <el-form-item>
		    <el-button type="primary" @click="selectPurchase">查询</el-button>
			 <el-button type="primary" @click="selectAll">查询所有</el-button>
		  </el-form-item>
		</el-form>
		
	  <el-table
		:data="tableData"
		border
		style="width: 100%">
		<el-table-column
		  prop="pnum"
		  label="采购清单号"
		  width="100">
		</el-table-column>
		<el-table-column
		  prop="wnum"
		  label="员工编号"
		  width="120">
		</el-table-column>
		<el-table-column
		  prop="pnumber"
		  label="采购数量"
		  width="120">
		</el-table-column>
		<el-table-column
		  prop="pprice"
		  label="采购总价"
		  width="120">
		</el-table-column>
		<el-table-column
		  prop="ptime"
		  label="采购时间"
		  width="120">
		</el-table-column>
		<el-table-column
		  prop="premarks"
		  label="备注"
		  width="100">
		</el-table-column>
	   
	  </el-table>
	  <!-- 分页 -->
	  <el-pagination
	    background
	    layout="prev, pager, next"
		:page-size="6"
	    :total="total"
		@current-change="page">
	  </el-pagination>
	</div>
  
</template>

<script>
  export default {
    methods: {
	  selectAll(){
		  window.location.reload()
	  },
	  selectPurchase() {
		  // alert('submit!');
		  const _this=this
		  const array_p=[] //array型
		  axios.get('http://localhost:8181/purchase/findById/'+_this.pnum).then(function(resp){//findById返回的是一个对象object型
			    array_p.push(resp.data) //将object型转换成array型，因为resp.data为object型，而_this.tableData需要接受一个array型，
			     console.log(resp)
		  		_this.tableData=array_p
				_this.total=1
		  })
	  },
	  page(currentPage){
		const _this=this
		axios.get('http://localhost:8181/purchase/findAll/'+currentPage+'/6').then(function(resp){
			_this.tableData=resp.data.content
			_this.total=resp.data.totalElements
		})
	  }
    },
	created() {
		const _this=this
		axios.get('http://localhost:8181/purchase/findAll/1/6').then(function(resp){
			console.log(resp)
			_this.tableData=resp.data.content
			_this.total=resp.data.totalElements
		})
	},
    data() {
      return {
        total:null,
		tableData:null,
		pnum: ''
		}
    }
  }
</script>


